package com.akeil.flash.utils;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.PlatformUI;

import com.akeil.flash.dialog.CheckPasswordDialog;
import com.akeil.flash.preferences.IPreferenceConstants;

import flash.Activator;

public class SecurityUtils {
	public static int CheckAuthentication(){
		final IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
		String storeUsername = preferenceStore.getString(IPreferenceConstants.SECURITY_USERNAME);
		String storePassword = preferenceStore.getString(IPreferenceConstants.SECURITY_PASSWORD);
		CheckPasswordDialog checkPasswordDialog = new CheckPasswordDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
		if(IDialogConstants.OK_ID == checkPasswordDialog.open()){
			if(storeUsername.equals(checkPasswordDialog.getUsername())
				&& 	storePassword.equals(checkPasswordDialog.getPassword())
					){
				return 0;
			}else{
				return -1;
			}
		}
		
		return 1;
	}
}